#!/usr/bin/env python3
import os
import time
from suntime import Sun


def getLocalHour(hour):
    hour = int(hour) + 8
    if hour >= 24:
        hour -= 24
    return hour


if __name__ == "__main__":
    latitude = 29.614298
    longitude = 106.331018

    sun = Sun(latitude, longitude)

    today_sr = sun.get_sunrise_time()
    today_ss = sun.get_sunset_time()

    hour_sr = getLocalHour(today_sr.strftime('%H'))
    hour_ss = getLocalHour(today_ss.strftime('%H')) - 1

    status = os.popen('/usr/local/bin/dark-mode status').read().strip()

    hour_now = int(time.strftime("%H"))
    if hour_now > hour_sr and hour_now < hour_ss:
        if status != 'off':
            print('off')
    else:
        if status != 'on':
            print('on')
